<?php 

Class ModuleVideoBitrateResult extends CmsCustomModule {
	
	private function getBitrate(){
		return array(
			rand(100, 10000),
			rand(100, 10000),
			rand(100, 10000),
		);
	}
	private function getReginHTML($regin, $list){
		$datas = '';
		$captures = AC::$video_bitrates;
		for($i=0, $ilen=rand(2, 10); $i < $ilen; $i++){
			if(rand(0, 3)){
				$v = $this->getBitrate();
				$capture = json_encode($captures);
				$datas .= '<input type="hidden" class="countrychart" name="country name '.$i.'" value="'.json_encode($v).'" capture='."'{$capture}'".' />';
			}else{
				$v = array(rand(1000, 100000));
				$capture = json_encode(array('NONE'));
				$datas .= '<input type="hidden" class="countrychart none" name="country name '.$i.'" value="'.json_encode($v).'" capture='."'{$capture}'".' />';
			}
		}
		return <<<HTML
 <dl><dt>{$regin}</dt><dd>{$datas}</dd></dl>
HTML;
	}
    protected function __renderHead()
    {
		$filters = array('dateby', 'startmonth', 'startyear', 'endmonth', 'endyear', 'startdate', 'enddate', 'country');
		foreach($_GET as $k=>$v){
			if(in_array($k, $filters)){
				$$k = $v;
			}
		}
		$startmonth = str_pad($startmonth, 2, 0, STR_PAD_LEFT);
		$endmonth = str_pad($endmonth, 2, 0, STR_PAD_LEFT);
		$curr_datetime = date("Y-m-d H:i:s");
		
		$str_date = '';
		if($dateby == 'date'){
			$str_date = "{$startdate} - {$enddate}";
		}else{
			$str_date = "{$startyear} - {$startmonth} to {$endyear} - {$endmonth}";
		}
		
		$str_country = transCountry($country);
		
		$country = json_decode($country);
		$country_html = '';
		foreach($country as $k=>$item){
			$country_html .= $this->getReginHTML($k, $item);
		}
		
		$dateby = ucwords( strtolower($dateby));
		
		$this->contents = <<<HTML
	<div id="result" class="video_bitrate_result">
		<div class="hd">
			<div class="utility">
				<a href="#" class="print">Print</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				Export to <a href="#">HTML</a>
			</div>
			<hr />
			<h1>Video Bitrate Report</h1>
			<div class="time">{$curr_datetime}</div><br />
			<div><b>By {$dateby}:</b> {$str_date}</div>
			<table class="nob"><tr><td valign="top" width="100"><b>Region/Country:</b>&nbsp;</td><td>{$str_country}</td></tr></table>
		</div>
		<div class="bd">
 {$country_html}
		</div>
	</div>
HTML;
    }
}
?>